<?php
/*
	我发起的项目
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;

if($_RQ['op']=='main'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	
	if(isset($_RQ['status'])){
		$params['status']=$_RQ['status'];
	}
	$list=pdo_getall('jy_zhongchou_project',$params);
	
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	else{
		$sum=0;
	}
	$return['list']=$list;
	set_html('title','我的项目');
	$return['sum']=$sum;
	exi($return);

}
//申请提现
if($_RQ['op']=='tixian'){
	if(!$_RQ['id']){
		exi('找不到项目信息！','error');
	}
	$post=array();
	$post['money']=0;
	$this->session('id',$_RQ['id']);
	 $user=pdo_get('jy_zhongchou_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	 $project=pdo_get('jy_zhongchou_project',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	if($_RQ['postdata']){
	   $postdata=get_postdata();
	   $money=$postdata['money'];
	   //被拉黑用户无法提现
	   if($user['status']==1){
		   exi('您已进入黑名单,无法提现，请联系管理员','error');
	   }
	   if(!$money||$money<=0){
		   exi('提现金额不规范，请重新填写提现金额','error');
	   } 
	   if($money>$project['cash']){
		   exi('提现金额不得大于可提现金额，请重新填写提现金额','error');
	   }
	   //创建一个状态为正在申请的提现记录
	   $insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'money'=>$money,
			'pid'=>$_RQ['id'],
			'status'=>0,
			'name'=>$postdata['name'],
			'bankcard'=>$postdata['bankcard'],
			'reason'=>$postdata['reason'],
			'type'=>$postdata['type'],
			'name'=>$postdata['name'],
			'createtime'=>TIMESTAMP
	   );
	   pdo_insert('jy_zhongchou_cashrecord',$insert);
	   //修改项目可提现金额
	   pdo_update('jy_zhongchou_project',array('cash'=>$project['cash']-$money),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	   exi('申请提现成功！','success','jy_zhongchou/home/cashrecord/');
	
}
     $return['post']=$post;
     $return['user']=$user;
     $return['project']=$project;
	 exi($return);
}
if($_RQ['op']=='submit'){
	$project=pdo_get('jy_zhongchou_project',array('uniacid'=>$_SESSION['uniacid'],'id'=>$this->session('id')));
	if($_RQ['postdata']){
	   $postdata=get_postdata();
	   $money=$postdata['money'];
	   //被拉黑用户无法提现
	   if($user['status']==1){
		   exi('您已进入黑名单,无法提现，请联系管理员','error');
	   }
	   if(!$money||$money<=0){
		   exi('提现金额不规范，请重新填写提现金额','error');
	   } 
	   if($money>$project['cash']){
		   exi('提现金额不得大于可提现金额，请重新填写提现金额','error');
	   }
	   //创建一个状态为正在申请的提现记录
	   $insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'money'=>$money,
			'pid'=>$this->session('id'),
			'status'=>0,
			'name'=>$postdata['name'],
			'bankcard'=>$postdata['bankcard'],
			'reason'=>$postdata['reason'],
			'type'=>$postdata['type'],
			'name'=>$postdata['name'],
			'createtime'=>TIMESTAMP
	   );
	   pdo_insert('jy_zhongchou_cashrecord',$insert);
	   //修改项目可提现金额
	   pdo_update('jy_zhongchou_project',array('cash'=>$project['cash']-$money),array('uniacid'=>$_SESSION['uniacid'],'id'=>$this->session('id')));
	   exi('申请提现成功！','success','jy_zhongchou/home/cashrecord/');
	
}
}
if($_RQ['op']=='del'){
	
	if(!$_RQ['id']){
		exi('项目不存在！','error');
	}
	
	pdo_delete('jy_zhongchou_project',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除成功！');

}